using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;

public partial class sendfgtmail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { 
            Manager mngr = new Manager(true,"ConnectionString");
            DataSet ds = mngr.ExecuteQuery("select id,email,fname,mname,lname,password from tbl_users where password is not null and len(password)<>0 and isdelete=0","pro_doc");
            Response.Write("not a post back");
            GridView1.Caption = ds.Tables[0].Rows.Count.ToString() + " record(s) found!";
            GridView1.DataSource = ds;
            GridView1.DataBind();
            mngr = null;
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Manager mngr = new Manager(true,"ConnectionString");
        foreach (GridViewRow gvr in GridView1.Rows)
        {
            CheckBox chk = (CheckBox)gvr.FindControl("chkSend");
            if (chk != null)
            {
                //chk.Checked = !chk.Checked;
                if (chk.Checked)
                {
                    string s= "Dear " +gvr.Cells[3].Text +", "+gvr.Cells[5].Text+","+"<br><br>";
                       s+="Your password for your Findadoc.com account is below:"+"<br><br>";;
                       s+="Email ID:   "+gvr.Cells[2].Text+"<br>"+"Password:  "+gvr.Cells[6].Text+"<br><br>"; 
                       s+="Please save this email for future reference."+"<br><br>";
                       s += "Sincerely," + "<br>" + "FindaDoc Support" + "<br>";
                       //Response.Write(s + "<br><br>");

                       mngr.sendMail(s, gvr.Cells[2].Text, "Findadoc", "Findadoc - Password", "info@findadoc.com","");
                       mngr.sendMail(s, "synapsetesting@gmail.com", "Findadoc", "Findadoc - Password", "info@findadoc.com","");
                          
                }
                
            }
        }
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        foreach (GridViewRow gvr in GridView1.Rows)
        {
            CheckBox chk = (CheckBox)gvr.FindControl("chkSend");
            if (chk != null)
            {
                if(CheckBox1.Checked)
                chk.Checked = true;
                else
                chk.Checked = false ;
            }
        }
    }
}
